<?php
//edit by peter 2017-04-10
include_once $_SERVER ['DOCUMENT_ROOT'] . '/upacp_demo_b2b/sdk/acp_service.php';
class ectools_payment_plugin_unionpayb2b_server extends ectools_payment_app {
    //异步返回方法 和同步的方法一样
    //edit by peter 2017-04-10
    public function callback(&$recv){
	$logger=com\unionpay\acp\sdk\LogUtil::getLogger();
	//银联返回整个$_POST,内含各种信息
	$logger->LogInfo("receive back notify: " . com\unionpay\acp\sdk\createLinkString ( $_POST, false, true ));
        $objMath = kernel::single('ectools_math');
        $money=$objMath->number_multiple(array($_POST['settleAmt'], 0.01));
	//商户号
        $merid = $this->getConf('mer_id', __CLASS__);
        $sign=$_POST['signature'];       
        $sign_method=$_POST['signMethod']; 
        $ret['payment_id'] =$_POST['orderId'];
        $ret['account'] = $_POST['merId'];
        $ret['bank'] = app::get('ectools')->_('银联');
        $ret['pay_account'] = app::get('ectools')->_('付款帐号');
        $ret['currency'] = 'CNY';
        $ret['money'] = $money;
        $ret['paycost'] = '0.000';
        $ret['cur_money'] =$money;
        $ret['tradeno'] = $_POST['traceNo'];
        // $ret['t_payed'] = strtotime($_POST['settleDate']) ? strtotime($_POST['settleDate']) : time();
        $ret['t_payed'] = time();
        $ret['pay_app_id'] = 'unionpayb2b';
        $ret['pay_type'] = 'online';
        $ret['memo'] = 'unionpayb2b';
        //校验签名
	$ret['status']='failed';
	if (isset($sign)){   
		if (com\unionpay\acp\sdk\AcpService::validate ( $_POST ) && $_POST['respCode']==00) {
		    $ret['status'] = 'succ';
		}
	}
        //判断respCode=00、A6后，对涉及资金类的交易，请再发起查询接口查询，确定交易成功后更新数据库。
	return $ret;
    }

   
}
